package com.jms.controller.web;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jms.controller.base.BaseController;
import com.jms.pageModel.base.Grid;
import com.jms.pageModel.base.Json;
import com.jms.pageModel.base.PageFilter;
import com.jms.pageModel.base.Tree;
import com.jms.pageModel.web.Mbgroup;
import com.jms.service.base.ServiceException;
import com.jms.service.web.MbgroupServiceI;

@Controller
@RequestMapping("/mbgroup")
public class MbgroupController extends BaseController {

	@Autowired
	private MbgroupServiceI mbgroupService;
	
	@RequestMapping("/manager")
	public String manager() {
		return "/admin/mbgroup";
	}
	
	@RequestMapping("/dataGrid")
	@ResponseBody
	public Grid dataGrid(Mbgroup mb, PageFilter ph) {
		Grid grid = new Grid();
		grid.setRows(mbgroupService.dataGrid(mb, ph));
		grid.setTotal(mbgroupService.count(mb, ph));
		return grid;
	}
	@RequestMapping("/tree")
	@ResponseBody
	public List<Tree> tree(HttpSession session) {
		return mbgroupService.tree();
	}


	@RequestMapping("/delete")
	@ResponseBody
	public Json delete(Long id) {
		Json j = new Json();
		try {
			mbgroupService.delete(id);
			j.setMsg("删除成功！");
			j.setSuccess(true);
		} catch (ServiceException e) {
			j.setMsg(e.getMessage());
		}
		return j;
	}
}
